import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from 'vuex-persistedstate'
Vue.use(Vuex)

const store = new Vuex.Store({
  // 插件：使用sessionStorage进行vuex持久化
  plugins: [createPersistedState({
    storage: window.sessionStorage
  })],

  state: {
    city: '',
    // -----------------------测试开始--------------------------------------
    // 添加默认播放列表-测试
    playList1: [{
      al: {
        id: 146316568,
        name: "爱人勿念",
        pic: 109951167534663460,
        picUrl: "https://p2.music.126.net/WyyEPeO_u4KIcMlS-pzl-A==/109951167534663453.jpg",
        pic_str: "109951167534663453",
      },
      id: 1954909440
    }],
    playListIndex1: 0,

    // Wn音乐播放条
    playList: [],
    trackIds: [],
    songIds:[],
    songsDetail:[],

    songIndex: 0,
    isPause: true,


    // ----------------------------------测试结束------------------------
    // 暂停按钮是否显示
    isbtnShow: true,
    // 当前时间
    currentTime: 0,
    // 歌曲总时长
    duration: 0,
    ///登录用户信息
    userInfo: null,
    // 当前音量
    volume: 1,
    goToPage: "/",
    currHeader: 0,
  },
  getters: {
    getUserInfo(state) {
      console.log("vuex-getUserInfo");
      console.log(state.userInfo);
      return state.userInfo;
    }
  },
  mutations: {


    //----- wn music player ----- 

    setTrackIds(state, trackIds1) {
      state.trackIds = trackIds1;
    },
    setPlayList(state, list) {
      state.playList = list;
    },
    setSongIds(state, list) {
      state.songIds = list;
    },
    setSongsDetail(state, list) {
      state.songsDetail = list;
    },
    setIsPause(state, flag) {
      console.log("setIsPause "+ flag);
      state.isPause = flag;
    },


    setCurrHeader(state, currHeader) {
      state.currHeader = currHeader;
    },
    setGoToPage(state, page) {
      state.goToPage = page;
    },
    updataData(state, data) {
      state.city = data
    },
    // ----------------------------------------------------------
    updateplayListIndex1(state, value) {
      state.playListIndex1 = value
      console.log("vuex:", state.playListIndex1);
    },
    updateplayList1(state, value) {
      console.log("更新后的音乐列表:");
      console.log(state.playList1);
      state.playList1 = value
    },
    // ----------------------------------------------------------
    updateIsBtnShow(state, value) {
      console.log("updateIsBtnShow "+ value);
      state.isbtnShow = value;
    },
    updateCurrentTime(state, value) {
      // console.log(this.state.currentTime);
      state.currentTime = value
    },
    updateDuration(state, value) {
      state.duration = value
    },
    // 保存登录信息
    updateUserInfo(state, userInfo) {
      // console.log("vuex-updateUserInfo: ");
      // console.log(userInfo);
      state.userInfo = userInfo;
    },
    updateVolume(state, value) {
      // console.log(state.volume);
      state.volume = value
    },
  },
  actions: {
  },
  modules: {
  }
});

export default store;